﻿using System;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using CorreoSocialWeb.Models;

using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

using System.Data.Entity.ModelConfiguration.Conventions;


namespace CorreoSocialWeb.Models
{
    //[Table("AspNetUsers")]
    public class ApplicationUser : IdentityUser
    {
        /* CAMPOS EXTRAS AGREGADOS PARA CORREO SOCIAL */
        [System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int UsuarioId { get; set; }

        public string Nombre { get; set; }

        public string Apellido { get; set; }

        public int DomicilioId { get; set; }

        public int DNI { get; set; }

        public DateTime FechaNacimiento { get; set; }

        public String NroTelefonoCelular { get; set; }

        public String NroTelefonoFijo { get; set; }

        public String FotoDNI1 { get; set; }
        public String FotoDNI2 { get; set; }
        public String FotoServicio1 { get; set; }
        public String FotoServicio2 { get; set; }

        public int Reputacion { get; set; }

        public Boolean EmailEnviado { get; set; }

        /* CAMPOS EXTRAS AGREGADOS PARA CORREO SOCIAL */

        public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
        {
            return Task.FromResult(GenerateUserIdentity(manager));
        }

        public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        public bool ValidarContraseña(string password)
        {
            return HashUtil.VerifyHashedPassword(this.PasswordHash, password);
        }

        public Usuario GetUsuario()
        {
            return new CorreoSocialDbContext().Usuarios.FirstOrDefault(x => x.Id.Equals(this.UsuarioId));
        }

        public int Estado { get; set; }

        [NotMapped]
        public EstadoUsuarioEnu EstadoEnu
        {
            get
            {
                return (EstadoUsuarioEnu)this.Estado;
            }
            set
            {
                this.Estado = (int)value;
            }
        }
    }
}
